package com.chat.utils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class StringUtil {
	public static boolean isNull(String str) {
		return str == null || str.trim().length() == 0;
	}
	public static boolean isNotNull(String str) {
		return !isNull(str);
	}
	@SuppressWarnings("rawtypes")
	public static List convertToList(String str,String regex){
		List list = null;
		String[]strArray = null;
		if(isNotNull(str)){
			strArray=str.split(regex);
			list = Arrays.asList(strArray);
		}
		return list;
	}
	public static boolean isZeroNull(String str) {
		return str == null || str.trim().length() == 0 || "0".equals(str);
	}
	public static boolean isNotZeroNull(String str) {
		return !isZeroNull(str);
	}
	public static boolean isNumeric(String str){
        String reg = "^[0-9]+(.[0-9]+)?$";
        return str.matches(reg);
    }
	public static boolean isInteger(String input){  
        Matcher mer = Pattern.compile("^[0-9]+$").matcher(input);  
        return mer.find();  
    }
	public static Date StringToDate(String str) throws ParseException {
		SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
		return formatter.parse(str);
	}
	public static String DateToString(Date date) {
		SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
		return formatter.format(date);
	}
}